package day5;

import org.junit.Test;

public class Demo {
	
	
	@Test
	public void test01() {
		Add add = new Add(5, 8);
		int result = add.getResult();
		System.out.println(add);
		System.out.println(result);
	}
	@Test
	public void test02() {
		Sub sub = new Sub(5, 8);
		int result = sub.getResult();
		System.out.println(sub);
		System.out.println(result);
	}
	@Test
	public void test03() {
		Multi multi = new Multi(5, 8);
		int result = multi.getResult();
		System.out.println(multi);
		System.out.println(result);
	}
	@Test
	public void test04() {
		Div div = new Div(88, 8);
		int result = div.getResult();
		System.out.println(div);
		System.out.println(result);
	}
	//继承什么就是什么，new子类对象赋值给父类；
	@Test
	public void test05() {
		AbstractCal cal = new Add(4,5);
		System.out.println(cal.getResult());
		//父类变量可以指向new出来的其他子类对象
		cal = new Sub(7,9);
		System.out.println(cal.getResult());
	}
	
	
	@Test
	public void test06() {
		AbstractCal cal = new Div(45,9);
		System.out.println(cal.getResult());
		cal = new Multi(44,9);
		System.out.println(cal.getResult());
		
	}
	@Test
	public void test07() {
		AbstractCal cal = new Div(45,9);
		fun(cal);
		
	
		cal = new Multi(44,9);
		fun(cal);
		//错误写法cal.fun()  调用不到cal里没有这个方法;
		//站在抽象cal的角度去看new出来的这个multi这个对象
		//这个变量cal只能看到父类里声明的方法
		
	}
	
	//形参声明父类类型。不写具体的子类类型，实参可以是任何new出来的子类对象
	
	public void fun(AbstractCal cal) {
		System.out.println(cal.getResult());
	}
	

}
